package com.tjetc.service.impl;

import com.tjetc.constant.CommonConstant;
import com.tjetc.context.BaseContext;
import com.tjetc.dao.AdminDao;
import com.tjetc.dao.impl.AdminDaoImpl;
import com.tjetc.pojo.dto.AdminDTO;
import com.tjetc.pojo.entity.Admin;
import com.tjetc.exception.LoginException;
import com.tjetc.service.AdminService;

import java.sql.SQLException;


/**
 * @Author: itda
 * @Date: 2024/5/9 15:07
 * @Description: 管理员业务实现类
 */
public class AdminServiceImpl implements AdminService {

    public static AdminDao adminDao = new AdminDaoImpl();

    @Override
    public void login(AdminDTO adminDTO) throws Exception {
        Admin admin = adminDao.getByName(adminDTO.getName());
        if (admin == null) {
            throw new LoginException(CommonConstant.USER_NAME_ERROR);
        }
        if (!admin.getPassword().equals(adminDTO.getPassword())) {
            throw new LoginException(CommonConstant.PASSWORD_ERROR);
        }
        BaseContext.setCurrentId(admin.getId());
        System.out.println(admin.getName() + CommonConstant.ADMIN_LOGIN_SUCCESS);
    }
}
